#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

#include "hk_camera.h"

bool g_exit = false;
void sigint_handler(int sig) {
    printf("捕获到 SIGINT 信号\n");
    printf("处理 SIGINT 信号...\n");
    g_exit = true;
}

int main(int argc, char* argv[])
{
    struct sigaction new_action, old_action;

    // 设置新的信号处理程序
    new_action.sa_handler = sigint_handler;
    sigemptyset(&new_action.sa_mask); // 清空信号屏蔽集
    new_action.sa_flags = 0;

    // 设置SIGINT信号的新处理程序
    if (sigaction(SIGINT, &new_action, &old_action) == -1) {
        perror("无法设置信号处理程序");
        return 1;
    }

    std::shared_ptr<hk_camera> app_ptr = std::make_shared<hk_camera>();
    app_ptr->start();

    while(1){
        if(g_exit)
            break;
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }

    app_ptr->stop();
    return 0;
}